<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京站智能网格化管理系统</title>
    <link rel="stylesheet" type="text/css" href="../lib/css/common.css">
    <link rel="stylesheet" href="../lib/css/iconFont/iconfont.css">
    <!-- <link rel="stylesheet" type="text/css" href="../lib/css/count.css"> -->
    <link rel="stylesheet" href="../lib/css/pagination.css">
    <!-- <link rel="stylesheet" type="text/css" href="../lib/css/station.css"> -->
    <link rel="stylesheet" type="text/css" href="../lib/css/jquery.datetimepicker.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="../lib/css/newcount.css">

</head>
<body>
<div class="station_grid wraper">
    <div class="searchwrap">
        <!-- 日期时间 -->
        <div class="searchelm searchtime1">
            <select name="status" id="status" class="select_option status">
                <option value="">全部</option>
                <option value="4">正常</option>
                <option value="1">报修</option>
                <option value="2">维修</option>
                <option value="3">验收</option>
            </select>
            <div class="select2_wrap" style="min-width:10rem;max-width:60%;">
                <select name="wxdep" id="wxdep" class="search_control wxdep" style="width:100%">
                </select>
            </div>
            <input type="text" id="datetimepicker" class="search_control" name="ptime_start">
            <input type="text" id="datetimepicker2" class="search_control" name="ptime_end">
            <input type="button" value="查询" id="lookUp1" class="lookUp"/>
        </div>
        <!-- 图表导出 切换 -->
        <div class="tabbar clearfix">
            <ul class="tab">
                <li class="tab_li" id="export_file" data-rel="2"><i class="icon iconfont icon-daochu"></i>导出</li>
            </ul>
        </div> 
    </div>
    <!-- echarts统计图表 -->
    <div class="main_content">
        <!-- 人员表格 -->
        <div class="station_shaow_detail nan">
            <table class="station_shaow_detail_table">
                <caption style="font-size: 2.4rem;">设备报修记录表</caption>
            </table>
            <div class="M-box1" style="font-size:10px;text-align:center;" id="page_string"></div>
        </div>
        <div class="lds-css block">
            <div class="lds-dual-ring">
                <div></div>
            </div>
        </div>
    </div>
</div>
</body>
<!-- <script type="text/javascript" src="/assets/js/jquery.1.10.1.js"></script> -->
<script type="text/javascript" src="../lib/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../lib/js/base.js"></script>
<script type="text/javascript" src="../lib/js/datetimepicker.js"></script>
<script type="text/javascript" src="../lib/js/jquery.pagination.js"></script>
<script type="text/javascript" src="../lib/js/select2.full.min.js"></script>
<script type="text/javascript" src="../lib/js/count.js"></script>
<script  type="text/javascript">
//查询
var page = 1,postDep='1'
$("#lookUp1").click(function () {
    var _data = {
        'page':page,
        'start_time':$('#datetimepicker').val(),
        'end_time':$('#datetimepicker2').val(),
        'dept':$('.wxdep').val()=='none'?'':$('.wxdep').val(),
        'status':$('.status').val()
    };
    devicePostRepairTable(_data)
});
function findDetail(e,ids){
    var _tr = $(e).parents('tr'),_ids = ids
    
    if($(e).hasClass('black_act')){
        var _loadingtxt = '<tr class="shaow_detail_title count_tr listalign listnone listloading"><td></td><td colspan="10" stylt="text-align:center">加载中。。。</td></tr>'
        _tr.after(_loadingtxt)
        $.ajax({
            type: "POST",
            url: serverUrl.base+serverUrl.count+'ajax_details',
            data:{
                reportid:_ids
            },
            cache: false,
            dataType: "json",
            success: function(res){
                if(res.code == '0'){
                    var _data=res.data,_data1 = _data.devinfo[0],_data2=_data.taskinfo
                    var _html=''
                    if(_data1.length != 0){
                        var _td1='<tr class="shaow_detail_title count_tr listalign list'+_ids+'"><td></td><td colspan="9">'
                            _td1 += '上报时间：<span class="listspan1">'+_data1.addtime +'</span>'
                            _td1 += ' 上报人：<span class="listspan">'+_data1.username +'</span>'
                            _td1 += '<td></tr>'
                        _html += _td1 
                        if(_data2.length != 0){
                            var _tds2= ''
                            for(var i=0;i<_data2.length;i++){
                                var _td2='<tr class="shaow_detail_title count_tr listalign list'+_ids+'"><td></td><td colspan="9">'
                                
                                var _txt = '维修',_resultTxt='正常'
                                if(_data2[i].type == '1'){
                                    _txt = '验收'
                                }
                                if(_data2[i].result == '0'){
                                    _resultTxt = _txt + '中'
                                }else if(_data2[i].result == '1'){
                                    _resultTxt = _txt + '完成'
                                }else if(_data2[i].result == '2'){
                                    _resultTxt = _txt + '故障'
                                }else if(_data2[i].result == '3'){
                                    _resultTxt = '超出范围'
                                }
                                _td2 += _txt +'时间：<span class="listspan1">'+ _data2[i].tasktime +'</span>'
                                _td2 += ' '+_txt+'人：<span class="listspan">'+_data2[i].username +'</span>'
                                _td2 += ' '+_txt+'截止时间：<span class="listspan1">'+_data2[i].taskdonetime +'</span>'
                                _td2 += ' '+_txt+'结果：<span class="listspan1">'+_resultTxt +'</span>'
                                _td2 += '<td></tr>' 
                                _tds2 +=_td2   
                            }
                        } 
                        
                        _html += _tds2  
                           
                    }else{
                        _html = '<tr class="shaow_detail_title count_tr listalign listnone"><td></td><td colspan="10" stylt="text-align:center">无数据</td></tr>'
                    }
                    _tr.after(_html)
                    $(e).removeClass('black_act') 
                    $(e).addClass('black2_act') 
                }else{}
                
            },
            complete:function(res){
                _tr.nextAll('.listloading').remove();
            }
        })
    }else{

        $(e).removeClass('black2_act') 
        $(e).addClass('black_act') 
        _tr.nextAll('.list'+_ids).remove();
        _tr.nextAll('.listnone').remove();
    }
    
}
//表格
function devicePostRepairTable(data){
    $('.lds-css').addClass('block')
    var _data = data
    $.ajax({
        url: serverUrl.base+serverUrl.count+'record',
        type:"POST",
        data: _data,
        dataType:"json",
        success: function (res) {
            $('.lds-css').removeClass('block')
            // 根据数据库取到结果拼接现在结果
            var _data = res.data
            $('.station_shaow_detail_table').createTable({data:_data,columns:[
                {name:'序号',field:'',ids:1,w:'4rem'},
                {name:'设备名称',field:'device_name',w:'4rem'},
                {name:'设备类型',field:'device_type_name',w:'4rem'},
                {name:'设备位置',field:'area_name',w:'4rem'},
                {name:'所属网格',field:'grid_name',w:'4rem'},
                {name:'设备所属部门',field:'department_name',w:'10rem'},
                {name:'报修时间',field:'report_addtime',w:'10rem'},
                {name:'维修所用时间',field:'ys',w:'10rem'},
                {name:'设备状态',field:'report_status',w:'10rem'},
                {name:'维修次数',field:'num',w:'10rem'},
                {name:'详情',field:'report_id',w:'10rem',cls:'list_resource',render:function(index,elm,data,tr){
                    var _btn = '<span class="black1 black_act" onclick="findDetail(this,'+elm+')">查看详情</span></td>',$btn = $(_btn)
                    return _btn
                }}
            ]})
            $("#page_string").html(res.result_page);
        }
    });
}
function common_request(elm){
    if(arguments[0]){
        page = arguments[0]
    }else{
        page = 1
    }
    $("#lookUp1").trigger('click')
    // var url="<?php echo site_url("device/index2");?>?inajax=1&r="+Math.random();

    // $.ajax({
    //    type: "POST",
    //    url: url ,
    //    data: data_,
    //    cache:false,
    //    dataType:"json",
    //    //async:false,
    //    success: function(msg){
    //        var shtml = '' ;
    //        var list = msg.resultinfo.list;
    //        if(msg.resultcode<0){
    //             BUI.Message.Alert("你没权限执行此操作" ,'error');
    //             return false ;
    //        }else if(msg.resultcode == 0 ){
    //             BUI.Message.Alert(msg.resultinfo.errmsg ,'error');
    //             return false ;              
    //        }else{
                
    //             showlist()
    //        }
    //    },
    //    beforeSend:function(){
    //       // $("#result_").html('<font color="red"><img src="/assets/img/progressbar_microsoft.gif"></font>');
    //    },
    //    error:function(){
    //        //BUI.Message.Alert('服务器繁忙请稍后' ,'error');
    //    }
    // });     
}
common_request()
//

//查询
function search_(){
    page = 1 ;
    common_request(1);  
}

//tab初始化
$('.tab .tab_li').each(function(index,elm){
    //console.log(index,elm)
    $(this).data('val',index)
})
//图表切换后的操作
$('.tab_li').on('click',function(elm){
    var $this = $(this)
    var _ids = $this.data('rel')?$this.data('rel'):$this.index()
    console.log(_ids)
   if(_ids== '0'){
        $(".educe").addClass("addli");
    }else if(_ids== '2'){
        //导出按钮    
        var _url=serverUrl.base+serverUrl.count+'recordexport?'+'start_time='+$('#datetimepicker').val()+'&end_time='+$('#datetimepicker2').val()
        if($('.wxdep').val() !='none'){
            _url += '&dept='+ $('.wxdep').val()
        }
        if($('.status').val()){
            _url += '&status='+ $('.status').val()
        }
        window.location.href = _url;return;
    }
})
$('.wxdep').rpSelect({url:serverUrl.base+serverUrl.count+serverUrl.dep,multiple:false,placeholder:'请选择设备管理部门',hasAll:true})

</script>
</html>

